{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# for test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a and b + c\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "operationList=['and','or','+','-','*'] #TODO:not, /\n",
    "# def func1(a,b,c):\n",
    "#     # 计算表达式：calculate_expression\n",
    "#     calculate_expression='a'+' '+operationList[0]+' '+'b'+' '+operationList[2]+' '+'c'\n",
    "#     print(calculate_expression)\n",
    "#     return eval(calculate_expression)\n",
    "\n",
    "# func1(1,2,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "计算表达式为： X[0] and X[1] or X[2]\n",
      "运算个数为： 2\n",
      "变量个数为： 3\n"
     ]
    }
   ],
   "source": [
    "class Operator:\n",
    "    def __init__(self,operations_times) -> None:\n",
    "        self.calculate_expression='X[0]'\n",
    "        self.operations_times=operations_times\n",
    "        self.virable_nums=self.operations_times+1\n",
    "        for i in range(self.operations_times):\n",
    "            # get a random operator\n",
    "            random_operator = random.sample(operationList,1)[0]\n",
    "            self.calculate_expression += ' '+random_operator+' '+f'X[{i+1}]'\n",
    "        # 展示生成的表达式\n",
    "        self.show()\n",
    "    def calulate(self,X):\n",
    "        return eval(self.calculate_expression)\n",
    "    def show(self)-> None:\n",
    "        # X是计算的变量列表/向量\n",
    "        print('计算表达式为：',self.calculate_expression)\n",
    "        print('运算次数：',self.operations_times)\n",
    "        print('变量个数：',self.virable_nums)\n",
    "operator = Operator(2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "45"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "operator.calulate([2,4])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "计算表达式为： X[0] + X[1] + X[2] * X[3] and X[4] - X[5] - X[6] - X[7] - X[8] + X[9] or X[10]\n",
      "运算个数为： 10\n",
      "变量个数为： 11\n",
      "[168, 167, 3, 44, 140, 18, 103, 181, 122, 161] -123\n",
      "[175, 32, 102, 127, 77, 119, 166, 53, 163, 160] -264\n",
      "[56, 187, 52, 199, 63, 124, 61, 51, 37, 26] -184\n",
      "[80, 66, 19, 194, 183, 56, 124, 161, 63, 145] -76\n",
      "[171, 8, 181, 74, 53, 144, 30, 32, 133, 89] -197\n",
      "[173, 139, 91, 141, 21, 110, 112, 115, 174, 119] -371\n",
      "[83, 185, 57, 139, 61, 2, 93, 12, 150, 162] -34\n",
      "[32, 73, 121, 85, 43, 8, 56, 98, 133, 117] -135\n",
      "[62, 39, 105, 52, 18, 190, 73, 188, 179, 155] -457\n",
      "[130, 178, 34, 47, 151, 95, 133, 118, 31, 156] -70\n"
     ]
    }
   ],
   "source": [
    "x_len=10 #运算长度为10\n",
    "\n",
    " # hidden law\n",
    "operation = Operator(x_len)\n",
    " # 用于生成数据点的辅助数据\n",
    "X_meta =[i for i in range(200)]\n",
    "\n",
    "# 数据集规模\n",
    "data_point_num=10\n",
    "\n",
    "for i in range(data_point_num):\n",
    "    x = random.sample(X_meta,x_len)\n",
    "    y = operation.calulate(x)\n",
    "    print(x,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "计算表达式为： X[0] - X[1] + X[2] + X[3] and X[4] - X[5] or X[6] * X[7] + X[8] - X[9] * X[10]\n",
      "运算个数为： 10\n",
      "变量个数为： 11\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[162, 146,   1,  42, 197, 135,  63, 127, 150, 175],\n",
       "       [  3,  28,  11, 124, 137,  89,  44, 178,  92, 160],\n",
       "       [109, 163, 181,  37, 134, 174,  72, 140, 157,  90],\n",
       "       [ 11, 128, 174,   7,  60,  63, 111, 105,  93,  65],\n",
       "       [ 28,  11,  26, 180,  89,  81,  70,  62, 164, 133],\n",
       "       [123,  95,  31,  86,  77, 117,  89, 110,  42, 154],\n",
       "       [ 22, 133,  38,  31, 125,  79, 192,  95,  93,  29],\n",
       "       [ 60,   0,  66,  31,  94,  92, 143, 133,  82, 189],\n",
       "       [107, 135,  25,  29,  89,  24, 190, 109, 196,   7],\n",
       "       [185, 157, 172, 104, 180,  81,   5,  13, 125,  66],\n",
       "       [186, 135, 191,   3,  40, 102, 165,  75, 151,  71],\n",
       "       [ 54,   8,  79,   2, 109,  41,   9,  97,   1,   7],\n",
       "       [ 70, 123,  65, 193,  62, 102, 149,  94,  41,  37],\n",
       "       [178,  43,  16, 191,  88,  18, 167, 185,  57, 155],\n",
       "       [ 90,  86, 137, 166, 192, 186,  13, 132,  27, 120],\n",
       "       [119,  94,  25, 155, 121, 111, 191,  12,  63,  87],\n",
       "       [ 34,  53, 152, 132,  75, 104, 101,  32, 197, 143],\n",
       "       [ 94,  29,  91, 107, 140,  78, 136,  85, 125, 130],\n",
       "       [ 52, 152,  66, 165,  42, 171,  21,  49,  60, 121],\n",
       "       [ 53, 123,  16,   9, 187,  93,  62, 191,   7, 120],\n",
       "       [ 25,  30,  32,   0,  15, 172, 152, 194,  16, 114],\n",
       "       [176, 137,   0, 155, 133,   3,  85,  19, 111, 178],\n",
       "       [  3,   8, 132,  13,  65,  77, 163, 185, 133,  61],\n",
       "       [ 27, 139,   3, 181, 165,  82, 150, 160,  68, 164],\n",
       "       [ 35,  73, 162,  89,  86,  54,  91,  65, 122, 130],\n",
       "       [ 58, 168,  17, 185,  52, 131,  76,  69, 191, 130],\n",
       "       [194,  91, 174,  89, 153, 141, 192,  52,  63,   5],\n",
       "       [ 56, 156,  15, 116, 118,  28, 142,  37, 136,  85],\n",
       "       [ 83, 129,  93, 160,  81,  33, 138, 173,  98,  70],\n",
       "       [158, 168,  52, 104, 175, 161,  37, 185,  98,  33],\n",
       "       [  3,  59, 137, 158, 149,   1,  33, 188,  54,  52],\n",
       "       [179,  53, 167, 156,  20, 175,  34,  69, 176, 155],\n",
       "       [ 73, 108,  50,  52, 182,   7, 184, 142,  22, 135],\n",
       "       [155,  68, 134, 127,  94,  88, 151, 176, 150, 106],\n",
       "       [ 28,  88, 109, 183, 129, 166, 114,  79, 173,  23],\n",
       "       [178,  90, 131, 133, 100, 194, 188, 182,  73, 143],\n",
       "       [146, 149, 167, 184, 176,  61,  36, 153,  50,  78],\n",
       "       [174, 143,   2,  40,  64, 102,   0,  97,  95,  94],\n",
       "       [ 42, 163,  93,   4, 112, 183, 198,  35, 122,  13],\n",
       "       [ 69, 138, 160,  63, 198, 112, 117,  24, 125,  25],\n",
       "       [117,  35,  17, 153,  51, 149,  25, 167,  50, 109],\n",
       "       [ 70, 142, 139,  89, 178, 113,   1,  54,  55,   3],\n",
       "       [ 12, 117, 106,  84, 167, 197, 147, 143, 110,  69],\n",
       "       [107,   3, 120,  25,  48, 140, 158, 147, 130,  55],\n",
       "       [ 66, 167,  21,  16,  19, 193,  83,  40, 164,  37],\n",
       "       [110, 142,   1, 164,  84,  27,  78,  62, 163, 181],\n",
       "       [ 27, 149,   7, 152,  44, 115,  17, 173, 108, 160],\n",
       "       [ 19,   4, 190, 121,  67,  28, 103, 176,  73,  61],\n",
       "       [ 44,  97, 168,   2, 104,  89,   3,  65,  32, 158],\n",
       "       [163, 194,  19,  79, 123, 105, 190,   2,  58,  11],\n",
       "       [122,  72, 131,  47, 181,  61, 140,  29, 179, 159],\n",
       "       [ 23, 123,  76, 165,  17, 126, 163,  71, 129, 181],\n",
       "       [149,  45, 113, 197, 189, 180,  74,   3, 132, 127],\n",
       "       [ 99,  59,  79,  23,  66, 137, 126,   6,  58,  83],\n",
       "       [186,  14, 193, 189, 136, 190, 177, 187, 183, 101],\n",
       "       [  4, 112,  65, 136, 184,  74, 111,  73, 165,  42],\n",
       "       [170,  45, 116,  66,  41,  69,   4,  18,  83, 198],\n",
       "       [ 24, 191,   5, 144, 190,  15, 194,  60, 115,  80],\n",
       "       [ 92, 175,  16, 133,  12,  79, 150, 126,  13, 144],\n",
       "       [177,  85, 164, 185, 151,  38, 140,  47, 102,  89],\n",
       "       [134, 140, 156,  28,   4,  68, 170, 190, 141, 198],\n",
       "       [143,  87, 194, 153,  24,  12,  90, 104,  49, 130],\n",
       "       [192, 144,  47, 120, 134,  73, 193, 153, 135, 131],\n",
       "       [  3, 141, 118, 121,  12, 181, 145, 166,   0,  25],\n",
       "       [ 36,  27,  86,  98, 172, 196,  24,   5,  21,  76],\n",
       "       [148, 109, 115, 108, 112,  58,  65,  13,   8,  86],\n",
       "       [ 73,  82,  12, 193, 109,  62,  68, 140, 177, 164],\n",
       "       [130,  21,  83,  28,  72, 107, 112, 139, 191,  47],\n",
       "       [131, 155,  88, 182,  39,  37, 173, 172, 119,  65],\n",
       "       [117, 173,  69,  70,  45,  24,  67,   8, 196,  35],\n",
       "       [112, 147,  72, 126,  46, 163, 132,  37,  56, 101],\n",
       "       [143,  22,  82,  69,  58, 141, 189,  72,  53, 122],\n",
       "       [116,  96,  92,  15, 178,  81, 156,  71,  99, 171],\n",
       "       [131,  77, 121,  94, 165, 187,  28,  21, 172, 142],\n",
       "       [ 18, 178,  13, 104, 164, 175,  14, 177,  41, 190],\n",
       "       [139,  20,  96,  48,  46, 198, 133,  91, 167, 199],\n",
       "       [ 43,  49,  82, 174,  47, 133, 119, 154,  20, 102],\n",
       "       [171, 150, 123, 122,  13, 132, 188, 105, 183,  70],\n",
       "       [115,  20,  98, 165,  86, 153,  79,   8,  59, 111],\n",
       "       [142,  24,  69,  33,  79, 189,  14, 102, 155,  68],\n",
       "       [162, 152,  23,  34,   3, 116,  69, 187, 132, 117],\n",
       "       [135, 196,  10,  70,  14, 154, 105,  99,  16, 103],\n",
       "       [136,  98, 107, 100,  78,  49, 179, 108,  84, 124],\n",
       "       [  7, 115, 143,  64, 152, 182, 110, 100,  58, 175],\n",
       "       [160,  36,   5,  68, 189, 117, 188,  44, 147, 184],\n",
       "       [137, 102, 151, 132,  60, 168,  59, 109,  18,  75],\n",
       "       [ 26, 143,  28,  79, 156,  20,  49,  77,  24, 181],\n",
       "       [ 93,  16,  81, 149,  49, 138, 168,   8,  20,  88],\n",
       "       [ 19, 126, 178, 146,  39, 177, 170,  13,  60,  90],\n",
       "       [ 73,  89,  18, 179,  65,  15,  23,  31, 143,   0],\n",
       "       [141, 115, 186, 188,  87,  23,  91,   1,  49, 163],\n",
       "       [ 66, 189, 187,  99,  84, 111,   6,  79,  10, 108],\n",
       "       [148, 114,  26,  95, 128, 102, 151, 153, 147, 133],\n",
       "       [ 87, 172,  69,  92,  63,  31,  15,  11, 138,  89],\n",
       "       [157,  83,  49,  71,  13, 105,  45, 174,  78, 136],\n",
       "       [ 77, 173,  76,  15,  63, 190,  95, 155, 120, 194],\n",
       "       [120,  16, 114, 101, 182,  12, 171, 185, 160,  47],\n",
       "       [111,  81, 173, 104,  31, 183,  52, 164, 123, 107],\n",
       "       [ 94,  36,  96, 101,  22, 110,  44, 167, 137,  52],\n",
       "       [195,  49,  99,  17, 179,  91,  16,  52,  46,  11]])"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " #运算个数为10\n",
    "x_len=10\n",
    "\n",
    " # hidden law\n",
    "operation = Operator(x_len)\n",
    "\n",
    " # 用于生成数据点的辅助数据\n",
    "X_meta =[i for i in range(200)]\n",
    "\n",
    "# 数据集规模\n",
    "data_point_num=100\n",
    "\n",
    "#生成的数据集\n",
    "X=[]\n",
    "Y=[]\n",
    "for i in range(data_point_num):\n",
    "    x = random.sample(X_meta,x_len)\n",
    "    y = operation.calulate(x)\n",
    "    X.extend(x)\n",
    "    Y.append(y)\n",
    "X = np.array(X)\n",
    "X.reshape([data_point_num,x_len])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "env4cv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
